 
#include <string.h>
#include <math.h>
#include "system.h"
#include "f1c100s_de.h"
#include "f1c100s_timer.h"
#include "f1c100s_intc.h"
#include "f1c100s_gpio.h"
#include "f1c100s_pwm.h"
#include "f1c100s_uart.h"
#include "arm32.h"
#include "time0.h"
#include "spi0_flash.h"
#include "sfud.h"
int main(void)
{
  system_init();            // Initialize clocks, mmu, cache, uart, ...
  arm32_interrupt_enable(); // Enable interrupts
  timer0_init();
  printf("\r\napp [SPI_FLASH] run. compiled_time %s %s\r\n", __DATE__, __TIME__);
  spi0_flash_init();
  uint32_t flash_id = spi0_flash_read_id();
  printf("flash_id:0x%lX\r\n\r\n", flash_id);
  sfud_init();

  uint8_t read[1024 * 4 * 4], write[1024 * 4 * 4];
  for (int i = 0; i < 1024 * 4 * 4; i++)
  {
    write[i] = (i * 2) & 0xff;
    read[i]=0;
  }
  sfud_erase(sfud_get_device(0), 0x200000, 4096 * 5);
  sfud_erase_write(sfud_get_device(0), 0x200000, 10, write);
  sfud_read(sfud_get_device(0), 0x200000, 256, read);
  for (int i = 0; i < 256; i++)
  {
    printf("%02X ", read[i]);
    if ((i + 1) % 16 == 0)
      printf("\r\n");

    if ((i + 1) % 256 == 0)
      printf("\r\n\r\n");
  }
  while (1)
  {
  }
}
